<?php
// if(!file_exists("ggload")){
// 	mkdir("ggload");
// }
// $path=$_FILES['img']['tmp_name'];
// move_uploaded_file($path,"./ggload".$_FILES['img']['name']);
// $link=mysqli_connect("localhost","root","root","2113");
// $title=$_POST['title'];
// $content=$_POST['content'];
// $imgurl="./ggload".$_FILES['img']['name'];
// $sql="INSERT INTO addnews(title,content,imgurl) VALUES('$title','$content','$imgurl')";
// $res=mysqli_query($link,$sql);
// if($res){
// 	echo "添加成功";
// }else{
// 	echo "添加失败";
// }



// print_r($_POST);
// print_r($_FILES);

// 把获取的数据添加到数据库
$title = $_POST['title'];
$content = $_POST['content'];
$typeValue = $_POST['type'];
$country = $_POST['country'];
// 文件存储 
if(!file_exists("uploads")){
	mkdir("uploads");
}

$path = $_FILES['imgFile']['tmp_name'];
$disPath = "uploads/".$_FILES['imgFile']['name'];
move_uploaded_file($path,$disPath);

// 添加时间
$addTime = time(); 

$link = mysqli_connect("localhost","root","root","2113");


$sql = "INSERT INTO addnews (title,content,imgurl,type,country,addTime) VALUES('$title','$content','$disPath','$typeValue','$country','$addTime')";


$res =  mysqli_query($link,$sql);

$arr = [];
if($res){
	$arr['info'] = "添加成功";
	$arr['status'] = 1;
}else{
	$arr['info'] = "添加失败";
	$arr['status'] = 0;
}

echo json_encode($arr);

// 更新之前的数据

?>